dojo.provide("apt.FilterPopover");
dojo.require("apt.Popover");

dojo.declare("apt.FilterPopover", [apt.Popover], {
    templateString: dojo.cache('apt.templates', 'FilterPopover.html'),
    start: '',
    end: '',
    license: '',
    contact: '',
		parent: '',
    
    constructor: function(data){
      this.inherited(arguments);
    },
    
		postCreate: function(){
      var b = dojo.query('body')[0];			
      this.placeAt(b, 'last');
			
			// Generate options for Departments
			dojo.place(this.generateDepartmentOptions(), this.departmentsNode);

			// Generate options for Shifts
			dojo.place(this.generateShiftOptions(), this.shiftsNode);

			// Generate options for resources
			dojo.place(this.generateResourceOptions(), this.resourcesNode);
    },
				
		generateOption: function(value, label){
      return '<option value="' + value + '">' + label + '</option>\n';
		},
		
		generateResourceOptions: function(){
			var resources = this.parent.stores.resources.query();
			var options = this.generateOption('*', 'All');
			for (var i=0; i < resources.length; i++) {
				options = options + this.generateOption(resources[i]['SmanId'], resources[i]['Name']);
			};			
			return dojo.create('select', {innerHTML: options, id: "filterResources" });
		},

		generateShiftOptions: function(){
			var shifts = this.parent.stores.shifts.query();
			var options = this.generateOption('*', 'All');
	
			for (var i=0; i < shifts.length; i++) {
				options = options + this.generateOption(shifts[i]['ShiftID'], shifts[i]['Description'] + " " + shifts[i]['StartTime'] + " - " + shifts[i]['EndTime'] );
			};
			return dojo.create('select', {innerHTML: options, id: "filterShifts" });
		},
		
		generateDepartmentOptions: function(){
			var departments = this.parent.stores.departments.query();
			var options = this.generateOption('*', 'All');
	
			for (var i=0; i < departments.length; i++) {
				options = options + this.generateOption(departments[i]['Code'], departments[i]['Description']);
			};
			return dojo.create('select', {innerHTML: options, id: "filterDepartments" });
		},

		filterData: function(e){
      dojo.stopEvent(e);
      dojo.style(this.domNode, 'display', 'none');
		},
		
		toggle: function(){
		},

    hide: function(e){
      dojo.stopEvent(e);
      dojo.style(this.domNode, 'display', 'none');
    }
		
});
